from typing import *


class Solution:

    def avoidFlood(self, rains: List[int]) -> List[int]:
        h = DefaultDict(bool)
        ans = [-1] * len(rains)
        a = []
        for i, v in enumerate(rains):
            if v == 0:
                ans[i] = 1
                a.append(i)
            else:
                if not h[v]:
                    h[v] = True
                else:
                    if len(a) == 0:
                        return []
                    else:
                        h[v] = False
                        ans[a.pop()] = v
        return ans


test = [[1,2,3,4],
[1,2,0,0,2,1],
[1,2,0,1,2],
[69,0,0,0,69],
[0,1,1]]

s = Solution()
for t in test:
    print(s.avoidFlood(t))